package cn.jesin.css.entity;

import cn.hutool.core.util.StrUtil;
import lombok.Data;

import java.util.*;

/**
 * @author 谷汉斌
 * @description
 * @createTime 2024/8/23 下午4:08
 */
@Data
public class UserConnection {
    private Integer id;
    private String username;
    private String creationLike;
    private String creationFavorite;
    private String authorFollow;
    private Date createTime;
    private Date updateTime;

    public Map<Integer, String> getCreationLikeMap() {
        if (StrUtil.isBlank(creationLike)) {
            return new HashMap<>();
        }
        String[] split = creationLike.split(":");
        Map<Integer, String> map = new HashMap<>();
        for (int i = 0; i < split.length; i++) {
            split[i] = split[i].trim();
            map.put(Integer.parseInt(split[i]),split[i]);
        }
        return map;
    }

    public Map<Integer, String> getCreationFavoriteMap() {
        if (StrUtil.isBlank(creationFavorite)) {
            return new HashMap<>();
        }
        String[] split = creationFavorite.split(":");
        Map<Integer, String> map = new HashMap<>();
        for (int i = 0; i < split.length; i++) {
            split[i] = split[i].trim();
            map.put( Integer.parseInt(split[i]),split[i]);
        }
        return map;
    }

    public Map<String, String> getAuthorFollowMap() {
        if (StrUtil.isBlank(authorFollow)) {
            return new HashMap<>();
        }
        String[] split = authorFollow.split(":");
        Map<String, String> map = new HashMap<>();
        for (int i = 0; i < split.length; i++) {
            split[i] = split[i].trim();
            map.put( split[i],split[i]);
        }
        return map;
    }

    public void setCreationLikeMap(Map<Integer, String> creationLike) {
        StringBuilder sb = new StringBuilder();
        for (Map.Entry<Integer, String> entry : creationLike.entrySet()) {
            sb.append(entry.getValue()).append(":");
        }
        this.creationLike = sb.toString();
    }

    public void setCreationFavoriteMap(Map<Integer, String> creationFavorite) {
        StringBuilder sb = new StringBuilder();
        for (Map.Entry<Integer, String> entry : creationFavorite.entrySet()) {
            sb.append(entry.getValue()).append(":");
        }
        this.creationFavorite = sb.toString();
    }

    public void setAuthorFollowMap(Map<String, String> authorFollow) {
        StringBuilder sb = new StringBuilder();
        for (Map.Entry<String, String> entry : authorFollow.entrySet()) {
            sb.append(entry.getValue()).append(":");
        }
        this.authorFollow = sb.toString();
    }
}
